import requests
from bs4 import BeautifulSoup
def gethtml(url):
    try:
        re=requests.get(url,timeout=10)
        re.raise_for_status()
        re.encoding="utf-8"
        print("获取成功")
        return re.text
    except:
        print("获取失败")
        return ""
def gethtmldata(html):
    soup=BeautifulSoup(html,"html.parser")
    div_ls=soup.find_all("div",{"class":"page_list"})
    ul_ls=div_ls[0].find_all("ul")
    all_ls=[]
    for ul in ul_ls:
        ls=[]
        if len(ul)==5:
            li_time=ul.find_all("li",{"class":"page_list_date"})
            ls.append(li_time[0].string)
            li_a=ul.find("a")
            ls.append(li_a.attrs["title"])
            ls.append(li_a.attrs["href"])
        all_ls.append(ls)
    return all_ls


def writehtmldata(ls):
    with open(r"温州职业技术学院.csv","w")as f:
        for line in ls:
            f.write(",".join(line)+"\n")
def main():
    url="https://www.wzvtc.cn/list/21.html"
    html=gethtml(url)
    ls=gethtmldata(html)
    writehtmldata(ls)

if __name__ == '__main__':
    main()